<template>
  <div class="app-container">
    <Ht-search-form
      v-show="showSearch"
      :advOptions="[]"
      :dictMap="dictMap"
      :formOptions="formOptions"
      :outputQueryParams="queryParams"
      :queryParams="queryParams"
      :defaultEventKey="defaultEventKey"
    ></Ht-search-form>

    <!--    <div class="page-label-block">-->
    <!--      <span class="color-block">|</span>-->
    <!--      <span class="page-label-name">-->
    <!--      租户管理-->
    <!--      </span>-->
    <!--    </div>-->

    <ht-table
      :defaultEventKey="defaultEventKey"
      ref="dataTable"
      :dictMap="dictMap"
      :multi-select="false"
      :opButtonList="opButtonList"
      :queryParams="queryParams"
      :reqConfig="regConfig"
      :showSerialNumber="false"
      :tableBindColumns="tableBindColumns"
    >
      <template v-slot:operate>
        <el-table-column align="left" fixed="right" label="操作" width="50">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '明细',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      append-to-body
      width="1024px"
    >
      <el-form ref="detailForm" :model="detailForm" :rules="rules" label-width="120px">
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>基本信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="批次流水号" prop="id">
                <el-input v-model="detailForm.id" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文标识号" prop="id">
                <el-input v-model="detailForm.pkgId" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="明细标识号" prop="dtlNo">
                <el-input v-model="detailForm.dtlNo" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="通讯状态" prop="status">
                <el-select style="width: 100%" v-model="detailForm.status" placeholder="通讯状态" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.PKG_STATUS"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="工作日期" prop="workdate">
                <el-date-picker
                  v-model="detailForm.workdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="CPG日期" prop="vdate">
                <el-date-picker
                  v-model="detailForm.vdate"
                  style="width: 100%"
                  type="date"
                  value-format="yyyyMMdd"
                  :disabled="true"
                />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="业务类型" prop="bizTypeCode">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.bizTypeCode === null || detailForm.bizTypeCode === undefined
                      ? ''
                      : detailForm.bizTypeCode + '-' + detailForm.bizTypeCodeDesc
                  "
                  placeholder="业务类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="业务种类" prop="bizCtgyCode">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.bizCtgyCode === null || detailForm.bizCtgyCode === undefined
                      ? ''
                      : detailForm.bizCtgyCode + '-' + detailForm.bizCtgyCodeDesc
                  "
                  placeholder="业务种类"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="记账标志" prop="cbflag">
                <el-select style="width: 100%" v-model="detailForm.cbflag" placeholder="记账标志" :disabled="true">
                  <el-option
                    v-for="dict in dictMap.CBFLAG"
                    :key="dict.value"
                    :label="`${dict.value}-${dict.text}`"
                    :value="dict.value"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="报文类型" prop="msgType">
                <el-select
                  style="width: 100%"
                  v-model="
                    detailForm.msgType === null || detailForm.msgType === undefined
                      ? ''
                      : detailForm.msgType + '-' + detailForm.msgTypeDesc
                  "
                  placeholder="报文类型"
                  :disabled="true"
                ></el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>付款人信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款行行号" prop="payerBrno">
                <el-input v-model="detailForm.payerBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="付款行行名" prop="payerBrname">
                <el-input v-model="detailForm.payerBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款人开户行行号" prop="payerAccBrno">
                <el-input v-model="detailForm.payerAccBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="付款人开户行行名" prop="payerAccBrname">
                <el-input v-model="detailForm.payerAccBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款人账号" prop="payerActno">
                <el-input v-model="detailForm.payerActno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="付款人名称" prop="payerName">
                <el-input v-model="detailForm.payerName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="付款人地址" prop="payerAddr">
                <el-input v-model="detailForm.payerAddr" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>收款人信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款行行号" prop="payeeBrno">
                <el-input v-model="detailForm.payeeBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款行行名" prop="payeeBrname">
                <el-input v-model="detailForm.payeeBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款人开户行行号" prop="payeeAccBrno">
                <el-input v-model="detailForm.payeeAccBrno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款人开户行行名" prop="payeeAccBrname">
                <el-input v-model="detailForm.payeeAccBrname" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款人账号" prop="payeeActno">
                <el-input v-model="detailForm.payeeActno" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="收款人名称" prop="payeeName">
                <el-input v-model="detailForm.payeeName" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="收款人地址" prop="payeeAddr">
                <el-input v-model="detailForm.payeeAddr" :disabled="true" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
        <el-card class="form-card txnInfo-card">
          <div slot="header" class="label-header-msg">
            <span>其他交易信息</span>
          </div>
          <el-row type="flex">
            <el-col :span="12">
              <el-form-item label="交易币种" prop="curcd">
                <el-input v-model="detailForm.curcd" :disabled="true" />
              </el-form-item>
            </el-col>

            <el-col :span="12">
              <el-form-item label="金额" prop="amount">
                <ht-amount-input v-model="detailForm.amount" placeholder="金额" :disable="true"></ht-amount-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row type="flex">
            <el-col :span="24">
              <el-form-item label="附言" prop="content">
                <el-input type="textarea" v-model="detailForm.content" maxlength="105" show-word-limit />
              </el-form-item>
            </el-col>
          </el-row>
        </el-card>
      </el-form>

      <div slot="footer" align="center" class="dialog-footer">
        <el-button type="primary" @click="save" v-loading.fullscreen.lock="loading">提 交</el-button>
        <el-button type="primary" @click="reset">重 置</el-button>
        <el-button type="primary" @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  apiUrlConfigEntryQuery,
  bepsBusinessCorrectEntryDetail,
  bepsBusinessCorrectEntrySave,
} from "@/api/cnaps/beps/413";
import { listPageMixin } from "@/libs/listPageMixin";
import HtAmountInput from "@/views/components/HtAmountInput";
import { amountThousandsFormatter } from "@/utils/table_col_formatter";
import { stopPayAnswerEntryAgree } from "@/api/cnaps/beps/412";
export default {
  name: "BepsBusinessCorrectEntry",
  mixins: [listPageMixin],
  components: { HtAmountInput },
  data() {
    return {
      defaultEventKey: "defaultEventKey",
      loading: false,
      // 查询参数
      queryParams: {
        idSeqNo: "",
        workdate1: "",
        workdate2: "",
        pkgNo: "",
      },
      rules: {
        payerBrno: [{ max: 105, message: "附言最大为105位", trigger: "blur" }],
      },
      // 搜索
      formOptions: [],
      //
      searchFormDictList: ["PKG_TYPE_413", "PKG_TYPE", "CBFLAG", "PKG_STATUS"],
      // 列信息
      regConfig: apiUrlConfigEntryQuery,

      tableBindColumns: [
        { prop: "id", label: "交易流水号", width: 180 },
        { prop: "vdate", label: "CPG日期", type: "date" },
        { prop: "workdate", label: "工作日期", type: "date" },
        { prop: "directSender", label: "发起直接参与机构", width: 150 },
        { prop: "directRecver", label: "接收直接参与机构", width: 150 },
        { prop: "pkgId", label: "报文标识号", width: 180 },
        { prop: "msgType", label: "报文类型号", dictCode: "PKG_TYPE", width: 240 },
        { prop: "pkgNo", label: "交易类型", dictCode: "PKG_TYPE_413", width: 240 },
        { prop: "dtlNum", label: "交易总笔数", width: 120 },
        {
          prop: "dtlAmount",
          label: "交易总金额",
          type: "price",
          width: 120,
        },
      ],

      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      openDetail: false,
      // 表单参数
      detailForm: {
        pkgNo: undefined,
        pkgNoDesc: undefined,
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
    };
  },
  mounted() {
    const formOptions = [
      // 普通搜索

      {
        type: "input",
        prop: "idSeqNo",
        defaultAttr: {
          size: "small",
          label: "交易流水号",
          placeholder: "请输入交易流水号",
        },
      },

      {
        type: "dates",
        nameObj: {
          startTimeName: "workdate1",
          endTimeName: "workdate2",
        },
        defaultAttr: {
          size: "small",
          label: "CPG日期",
          placeholder: ["请输入CPG开始日期", "请输入CPG结束日期"],
          format: "yyyy-MM-dd",
          valueFormat: "yyyyMMdd",
        },
      },

      //todo amount

      {
        type: "dict",
        dict: "PKG_TYPE_413",
        prop: "pkgNo",
        defaultAttr: {
          size: "small",
          label: "交易类型",
          placeholder: "请输入交易类型",
        },
      },
    ];
    this.formOptions = formOptions;
    this.dictMapAsync = this.getDictMap();
  },
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */

    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      bepsBusinessCorrectEntryDetail(row.id, row.pkgNo).then((response) => {
        this.title = "业务冲正申请录入明细";
        this.detailForm = response.result;
        this.open = true;
      });
    },

    //提交按钮
    save() {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          bepsBusinessCorrectEntrySave(this.detailForm)
            .then((response) => {
              this.msgSuccess("成功");
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },

    //重置按钮
    reset() {
      this.resetForm("detailForm");
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
